package com.hvilela;

import java.awt.Dimension;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.lang.ref.SoftReference;

import javax.imageio.ImageIO;

/**
 * @author Henrique de Souza Vilela
 * henrique.vilela@gmail.com
 */
public class Entry implements Comparable<Entry> {

	protected File file;

	private BufferedImage image;

	private Point position;
	
	private Dimension area;
	
	private int weight = 1;

	public Entry(File file) {
		this.file = file;
	}

	public BufferedImage getImage() throws IOException {
		BufferedImage cache = image;

		if (cache == null) {
			System.out.println("loading " + file);
			cache = ImageIO.read(file);

			image = cache;
		}

		return cache;
	}

	public Point getPosition() {
		return position;
	}
	
	public void setPosition(Point position) {
		this.position = position;
	}

	public Dimension getArea() {
		return area;
	}

	public void setArea(Dimension area) {
		this.area = area;
	}

	public int getWeight() {
		return weight;
	}
	
	public void setWeight(int weight) {
		this.weight = weight;
	}

	@Override
	public int compareTo(Entry entry) {
		return weight - entry.weight;
	}
}